package com.mall.product.controller;

import com.mall.common.response.CommonResponse;
import com.mall.entity.TbSpeclification;
import com.mall.product.service.ISpeclificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * speclification控制器
 * created with IntelliJ IDEA
 *
 * @author ASUS
 * @Auther: W
 * @Date: 2021/07/16/14:54
 * Other:  规格大选项
 * @date 2021/07/18
 */
@RestController
@RequestMapping("/spec")
@CrossOrigin
public class SpeclificationController {

    @Autowired
    private ISpeclificationService speclificationService;

    /**
     * 查询所有
     *
     * @return {@link List<TbSpeclification>}
     */
    @GetMapping("/findAll")
    public List<TbSpeclification> findAll() {
        return speclificationService.findAll();
    }

    /**
     * 查询规格列表
     *
     * @param name 名称
     * @return {@link Map<String, Object>}
     */
    @GetMapping("/findList")
    public List<Map> findList(String name) {
        return speclificationService.findList(name);
    }

    /**
     * 添加商品规格
     *
     * @param speclification speclification
     * @return boolean
     */
    @PostMapping("/addSpec")
    public boolean addSpec(@RequestBody TbSpeclification speclification) {
        return speclificationService.addSpec(speclification);
    }

    @PostMapping(value = "/update",produces = "application/json;utf-8")
    public CommonResponse update(@RequestBody TbSpeclification speclification){
        return speclificationService.update(speclification);
    }


    /**
     * 查询单个
     *
     * @param name 的名字
     * @return {@link TbSpeclification}
     */
    @GetMapping("/findOne")
    public TbSpeclification findOne(String name) {
        return speclificationService.findOne(name);
    }

    /**
     * 回显，根据ID查询
     * @param id
     * @return
     */
    @GetMapping("/findByid")
    public List<Map> findByid(Integer id){
        return speclificationService.findByid(id);
    }

    @DeleteMapping("/deleteById")
    public CommonResponse deleteById(Integer id){
        return speclificationService.deleteById(id);
    }


    @DeleteMapping("/batchDelete")
    public CommonResponse batchDelete(Integer[] ids){
        return speclificationService.batchDelete(ids);
    }

}
